
local func = {}

func['铠巨'] = function(count,hero,player)
    local count = 0
    hero:loop(120*1000,function()
        hero:add('生命恢复加成',2)
        count = count + 2
    end)
    hero:event '英雄-开始复活'(function()
        local ex = math.ceil(count/2)
        count = count - ex
        hero:add('生命恢复加成',-ex)
    end)
end

func['超巨'] = function(count,hero,player)
    hero:add_skill('高温蒸汽')
end

func['咖喱棒'] = function(count,hero,player)
    hero:add_skill('咖喱棒')
end

func['锻造熔炉'] = function(count,hero,player)
    -- for a=1,3  do
    --     local name = random_item_name(math.random(1,2))
    --     local item = hero_add_item(hero,name)
    -- end
    player:set_data('黑市折扣',player:get_data('黑市折扣',0) + 10)
end

func['魔术戏法'] = function(count,hero,player)
    hero:event '单位-D闪完成'(function(_,_,angle)
        local damage = hero:get('全属性') * 1
        local num = 5
        local lock = {}
        for a=1,num do
            local r = angle + (a-num/2 - 0.5)/num*360
            local mover = hero:launch_wave([[KP_TX_msxf.mdl]],r,1200,600)
            sc.loopUnit(0.03,mover,120,function(group,unit)
                if unit:is_enemy(hero) then
                    hero:create_damage(unit,damage)
                end
            end):set_lock(lock)
        end
    end)
end

func['无影之弦'] = function(count,hero,player)
    hero:add_buff '属性转化'{
        key1 = '攻击距离',
        key2 = '攻击速度',
        data1 = 150,
        data2 = 5,
        max = 50,
    }
end


func['弑君者'] = function(count,hero,player)
    hero:add('对BOSS增伤',10)
    hero:event '英雄-击杀单位'(function(_,_,unit)
        if unit:is_type('领主') then
            hero:add('对BOSS增伤',2)
        end
    end)
end


func['终结者'] = function(count,hero,player)
    hero:add_skill('终结者')
end

func['未来战士'] = function(count,hero,player)
    hero:event '单位-召唤单位'(function(_,_,target)
        if target.name=='召唤物-终结者' and target.title=='终结者' then
            target:event '单位-攻击命中'(function()
                if math.random(100)<=15 then
                    local unit = hero:create_unit('召唤物-终结者',target:get_point(),0)
                    unit.title = '终结者-分裂体'
                    unit.owner_unit = hero
                    unit:set('攻击间隔',target:get('攻击间隔'))
                    unit:set('基础攻击',target:get('攻击'))
                    unit:set('攻击速度',target:get('攻击速度'))
                    unit:set('生命上限',target:get('生命上限'))
                    unit:set('基础护甲',target:get('基础护甲'))
                    unit:add_restriction '蝗虫'
                    target:event '单位-被召唤结束'(function()
                        unit:remove()
                    end)
                end
            end)
        end
    end)
end

func['融合之力'] = function(count,hero,player)
    local num1 = 0
    local num2 = 0
    hero:add_buff '属性转化'{
        key1 = '多重伤害',
        key2 = '物理伤害',
        data1 = 2,
        data2 = 0.5,
    }
    hero:add_buff '属性转化'{
        key1 = '弹射伤害',
        key2 = '魔法伤害',
        data1 = 2,
        data2 = 0.5,
    }
end

func['多重之力'] = function(count,hero,player)
    hero:add_buff '属性转化'{
        key1 = '多重数量',
        key2 = '多重伤害',
        data2 = 3,
    }
    if player:get_data('完成组合-多重之力') and player:get_data('完成组合-弹射之力') then
        player:notify('天赋-添加新组合',player,'融合之力激活',true)
    end
end

func['弹射之力'] = function(count,hero,player)
    hero:add_buff '属性转化'{
        key1 = '弹射次数',
        key2 = '弹射伤害',
        data2 = 3,
    }
    if player:get_data('完成组合-多重之力') and player:get_data('完成组合-弹射之力') then
        player:notify('天赋-添加新组合',player,'融合之力激活',true)
    end
end

func['圣契金律'] = function(count,hero,player)
    hero:loop(60 * 1000,function()
        local gold = 1000
        player:add('金币',gold)
        player:send_msg(('圣契金律：获得金币%d'):format(gold))
    end)
end

func['英魂融合'] = function(count,hero,player)
    hero:create_jx_item()
end

func['远射之力'] = function(count,hero,player)
    hero:add('攻击距离',hero:get('攻击距离')*0.15)
end

local list = {
    {'炼魂法阵','杀敌怪','杀敌'},
    {'金石脉动','金币怪','金币'},
    {'遗知灌注','经验怪','经验'},
}
for _,da in ipairs(list) do
    local name = da[1]
    local unit_name = da[2]
    local key = da[3]
    func[name] = function(count,hero,player)
        player:event '玩家-创建敌人'(function(_,player,unit)
            if unit.name==unit_name then
                unit[key] = (unit[key] or 0) * 1.2
            end
        end)
    end
end


func['秘境馈赠'] = function(count,hero,player)
    local list = player:get_data('装备吞噬列表') or {}
    local num = 1
    for _,it in ipairs(list) do
        num = num + 1
    end
    
    hero:add('装备加成',math.min(2*num,30))
    if num<15 then
        hero:event '单位-吞噬物品完成'(function(trg,hero,item)
            num = num + 1
            hero:add('装备加成',2)
            if num>=15 then
                trg:remove()
            end
        end)
    end
end

func['锻造之王'] = function(count,hero,player)
    hero:loop(60 * 1000,function()
        local name = random_item_name(math.random(1,3))
        local item = hero_add_item(hero,name)
        player:send_msg(('锻造之王：%s'):format(item:get_title()))
    end)
end

func['V我50'] = function(count,hero,player)
    hero:loop(5 * 1000,function()
        player:add('金币',50)
    end)
end

func['残缺剑诀'] = function(count,hero,player)
    hero:add_skill('残缺剑诀')
end
func['不焚者'] = function(count,hero,player)
    hero:add_skill('龙息')
end

func['红莲斩'] = function(count,hero,player)
    local skill = hero:find_skill('红莲斩')
    if skill then
        skill.cool = skill.cool - 2
        skill.rate = 3
    end
end

func['全境守护'] = function(count,hero,player)
    hero:add_skill('喷射吐息')
end

local skill_list = {
    {'红莲奥义斩','红莲斩','红莲奥义斩'},
    {'天罡剑诀','残缺剑诀','天罡剑诀'},
}
for _,da in ipairs(skill_list) do
    local name = da[1]
    local skill1 = da[2]
    local skill2 = da[3]
    func[name] = function(count,hero,player)
        local skill = hero:find_skill(skill1)
        if skill then
            skill:remove()
        end
        hero:add_skill(skill2)
    end
end

func['被污染的saber'] = function(count,hero,player)
    local count = 0
    hero:event '单位-攻击触发被动'(function(trg,_,_,skill)
        if skill.name=='EX咖喱棒' then
            count = count + 1
            if count>=20 then
                count = 0
                hero:add_buff '临时属性'{
                    time = 10,
                    art = [[羁绊卡牌\稀有\KP_xy_10.blp]],
                    title = skill.title,
                    tip = [[暴击率/暴击伤害提升]],
                    sx = {
                        ['暴击几率'] = 10,
                        ['暴击伤害'] = 50,
                    }
                }
            end
        end
    end)
end

func['青龙觉醒'] = function(count,hero,player)
    local num1 = 0
    hero:loop(1000,function()
        local count1 = - math.min(math.floor(math.max(unit:get('攻击速度') - 500,0)/50) * 0.02,0.01)
        hero:add('攻击间隔',count1 - num1)
        num1 = count1
    end)
end

func['白虎觉醒'] = function(count,hero,player)
    hero:add_buff '属性转化'{
        key1 = '生命上限',
        key2 = '基础攻击',
        data1 = 1000,
        data2 = 5,
    }
end

func['发育之心'] = function(count,hero,player)
    hero:event '单位-英雄升级'(function(trg,hero)
        if hero.level>=25 then
            trg:remove()
            hero:add('经验加成',10)
            hero:add('杀敌加成',10)
            hero:add('每秒金币',10)
        end
    end)
end

func['灵力萃取'] = function(count,hero,player)
    collate_item(hero,'转生之源')
end

func['副本密匙'] = function(count,hero,player)
    local item = hero:create_jx_item()
end


return func